<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .banner {
            height: 225px;
        }
        .banner .img {
        	width: 100%;
            height: 100%;
        	vertical-align: middle;
        }
        .back {
        	height: 20px;
        	padding: 14px 18px;
        	position: absolute;
        	left: 0;
        	top: 10px;
        }
        .main {
        	padding: 15px;
        	background-color: #fff;
        	margin-bottom: 6px;
        }
        .main .title {
			color: #333;
			font-size: 16px;
			margin-bottom: 10px;
        }
        .main .desc {
        	font-size: 12px;
        	color: #999;
        	margin-bottom: 13px;
        }
        .main .price_box {
        	overflow: hidden;
        }
        .main .price_box {
        	overflow: hidden;
        }
        .main .price_box .price {
        	line-height: 28px;
        	float: left;
        	font-size: 17px;
        	color: #e62442;
        }
        .main .price_box .cart {
        	width: 82px;
        	height: 28px;
        	line-height: 28px;
        	float: right;
        	color: #fff;
        	text-align: center;
        	border-radius: 5px;
        	background-color: #e62442;
        	font-size: 12px;
        }
        .evaluate_box {
        	background-color: #fff;
        }
        .evaluate_box .evaluate_title {
			height: 40px;
			line-height: 40px;
			padding: 0 15px;
			color: #333;
        	font-size: 12px;
        	border-bottom: 1px solid #e8e8e8;
        }
        .evaluate_box .evaluate_title span {
        	color: #999;
        }
        .evaluate_box .content ul li .li_box {
        	display: -webkit-box;
        	display: -webkit-flex;
        	padding: 15px;
        	border-bottom: 1px solid #e8e8e8;
        }
        .evaluate_box .content ul li .li_box .li_boxl .li_img {
			width: 43px;
			height: 43px;
			border-radius: 50%;
			overflow: hidden;
        }
        .evaluate_box .content ul li .li_box .li_boxl .li_img img {
        	width: 100%;
        	height: 100%;
        	object-fit: cover;
        }
        .evaluate_box .content ul li .li_box .li_boxr {
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	padding-left: 6px;
        }
        .evaluate_box .content ul li .li_box .li_boxr .name {
        	font-size: 14px;
        	color: #333;
        	margin-bottom: 8px;
        }
        .evaluate_box .content ul li .li_box .li_boxr .evaluate {
        	font-size: 12px;
        	color: #999;
        	display: -webkit-box;
        	-webkit-box-align: center;
        	margin-bottom: 15px;
        }
        .evaluate_box .content ul li .li_box .li_boxr .evaluate .evaluate_good {
        	color: #ffa82c;
        	display: block;
        }
        .evaluate_box .content ul li .li_box .li_boxr .evaluate .evaluate_bad {
        	color: #999;
        	display: block;
        }
        .evaluate_box .content ul li .li_box .li_boxr .evaluate img {
        	height: 12px;
        	margin-left: 3px;
        	display: block;
        }
        .evaluate_box .content ul li .li_box .li_boxr .evaluate_content {
			font-size: 14px;
			color: #333;
        }
        .evaluate_box .all_evaluate {
        	height: 40px;
        	line-height: 40px;
        	color: #999;
        	font-size: 12px;
        	text-align: center;
            display: none;
        }
        .without_data{
            display: none;
            color:#ccc;
            text-align:center;
            padding-top: 15px;
            background-color: #f8f8f8;
        }
        .banner .img{
            object-fit: cover;
        }
    </style>
</head>
<body>
    <div class="banner">
    	<img class="img" src="../image/default.png">
        <span class="back_span">
    	   <img class="back" src="../image/back.png" onclick="api.closeWin();" tapmode>
        </span>
    </div>
    <div class="main">
    	<div class="title"></div>
    	<div class="desc"></div>
    	<div class="price_box">
    		<div class="price">RM<span class="price_span"></span></div>
    		<div class="cart" onclick="fnAddCart();" tapmode>加入购物车</div>
    	</div>
    </div>
    <div class="evaluate_box">
    	<div class="evaluate_title">商品评价<span>（<span class="comment_num">0</span>）</span></div>
    	<div class="content">
            <div class="without_data">暂无评价</div>
    		<ul id="comment_ul">
	<!--     		<li>
	    			<div class="li_box">
	    				<div class="li_boxl">
	    					<div class="li_img">
	    						<img src="../image/temp/1.png">
	    					</div>
	    				</div>
	    				<div class="li_boxr">
	    					<div class="name">用户昵称</div>
							<div class="evaluate">商品： <span class="evaluate_good">好评</span><img src="../image/evaluate_good.png"></div>
							<div class="evaluate_content">很好吃</div>
	    				</div>
	    			</div>
	    		</li> -->
	    	</ul>
    	</div>
    	<div class="all_evaluate" tapmode onclick="fnAllEvaluate();">查看全部评价</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="commentTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li>
            <div class="li_box">
                <div class="li_boxl">
                    <div class="li_img">
                        <img src="{{=formatVideoImg(it[i]['img'])}}">
                    </div>
                </div>
                <div class="li_boxr">
                    <div class="name">{{=it[i]['nickname']}}</div>
                    <div class="evaluate">
                        商品： 
                        {{if(it[i]['opinion'] == 1){ }}
                            <span class="evaluate_good">好评</span><img src="../image/evaluate_good.png">
                        {{ }else{ }}
                            <span class="evaluate_bad">差评</span><img src="../image/evaluate_bad.png">

                        {{ }; }}
                    </div>
                    <div class="evaluate_content">{{=it[i]['content']}}</div>
                    {{ if(it[i]['pictures']){ }}
                        <div class="goods_img_box">
                            {{for(var j=0;j<it[i]['pictures'].length;j++){ }}
                                <div class="goods_img">
                                    <img src="{{=formatVideoImg(it[i]['pictures'][j]['img'])}}">
                                </div>
                            {{ }; }}
                        </div>
                    {{ }; }}
                </div>
            </div>
        </li>
    {{ }; }}
</script>
<script type="text/javascript">

    var price; // 防止报错 - tim

    apiready = function(){
        id = api.pageParam.id;
        api.ajax({
            url: rootPath+'/api/goods/goods_detail',
            method: 'get',
            cache:true,
            data: {
                values: { 
                    id: id,
                },

            }
        }, function(ret, err) {
            if (ret) {
                if(ret.status == 200) {
                    var img = formatVideoImg(ret.data.goods_img);
                    $('.img').attr('src',img);
                    $('.title').text(ret.data.goods_name);
                    $('.desc').html(ret.data.desc);
                    $('.price_span').text(ret.data.price);
                    price = ret.data.price?ret.data.price:0;
                    $('.comment_num').text(ret.data.comment_num);
                    if(ret.data.comment_num == 0){
                        $(".without_data").show();
                    }else{
                        $(".without_data").hide();
                    }
                }
            } else {
                showError(err.code,err.msg);
            }
        });

        fnGetComment();
    };

    // 全部评价
    function fnAllEvaluate() {
        api.openWin({
            name: 'all_evaluate',
            url: 'all_evaluate.html',
            pageParam: {
                goods_id:id,
            }
        });
    }

    function fnAddCart() {
        api.sendEvent({
            name: 'addCartEvent',
            extra: {
                goods_id: id, 
                price: price
            }
        });
        api.toast({
            msg: '加入购物车成功',
            location:'middle'
        });
    }

    function fnGetComment(type) {
        api.ajax({
            url: rootPath+'/api/shop/get_comment',
            method: 'post',
            data: {
                values: { 
                    goods_id: id,
                    page_num :5
                },

            }
        }, function(ret, err) {
           if(type == 1) {
                $('#comment_ul').empty();
            }
            if (ret) {
                if(ret.status == 200) {
                    $('.without_data').hide();
                    $('.all_evaluate').show();
                    appendDotData(ret.data,'commentTpl','comment_ul',true,false);
                }
            } else {
                api.toast({
                    msg: err.msg,
                    location : 'middle'
                });
            }
            if(type == 1) {
                // 是下拉刷新的，要收回
                api.refreshHeaderLoadDone();
            }
            if(type == 2) {
                //上拉给点假时间,好看些         
                setTimeout(function(){
                    $(".loading").hide();
                },1000);
            }else {
                $('.loading').hide();

            }
        });
    }
</script>
</html>